#include "doc.hpp"

Doc::Doc(){
	pp=0;
	pc=0;
	pf=0;
	ps=0;
	label="";
}

void Doc::addTerm(Term &t){
	if(!t.added){
		terms.push_back(&t);
		update(t);
		t.added=true;
	}
}

void Doc::print(std::ostream &o){
	/*
	std::cout << "label = " << label << std::endl;
	std::cout << "pp = " << pp << std::endl;
	std::cout << "pc = " << pc << std::endl;
	std::cout << "pf = " << pf << std::endl;
	std::cout << "ps = " << ps << std::endl;
	*/
	o << label << std::endl;
}

void Doc::update(Term &t){
	if(label == ""){
		pp=std::log(t.pp);
		pc=std::log(t.pc);
		pf=std::log(t.pf);
		ps=std::log(t.ps);
		/*
		std::cout << "initial" << std::endl;
		std::cout << "label = " << label << std::endl;
		std::cout << "pp = " << t.pp << std::endl;
		std::cout << "pc = " << t.pc << std::endl;
		std::cout << "pf = " << t.pf << std::endl;
		std::cout << "ps = " << t.ps << std::endl;
		*/
	}
	pp+=std::log(t.ppt);
	pc+=std::log(t.pct);
	pf+=std::log(t.pft);
	ps+=std::log(t.pst);
	/*
	std::cout << "label = " << label << std::endl;
	std::cout << "pp = " << pp << std::endl;
	std::cout << "pc = " << pc << std::endl;
	std::cout << "pf = " << pf << std::endl;
	std::cout << "ps = " << ps << std::endl;
	*/
	if(pp > pc && pp > pf && pp > ps){
		label = "project";
	}
	else if(pc > pp && pc > pf && pc > ps){
		label = "course";
	}
	else if(pf > pp && pf > pc && pf > ps){
		label = "faculty";
	}
	else{
		label = "student";
	}
}